package com.tbit.uqbike.client.service.impl;

import com.tbit.uqbike.client.dao.log.UserWeightLogDao;
import com.tbit.uqbike.client.pojo.UserWeightLog;
import com.tbit.uqbike.client.pojo.vo.UserWeightLogQueryReqVO;
import com.tbit.uqbike.client.pojo.vo.UserWeightLogRespVO;
import com.tbit.uqbike.client.service.UserWeightLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author <a href="mailto:li.yao@tbit.com.cn">yao</a>
 * @version 4.2.4
 * @since 2024/12/30 17:57
 */
@Service
public class UserWeightLogServiceImpl implements UserWeightLogService {

    @Resource
    private UserWeightLogDao userWeightLogDao;

    @Override
    public List<UserWeightLogRespVO> getListRange(UserWeightLogQueryReqVO reqVO) {
        return userWeightLogDao.selectListRange(reqVO);
    }

    @Override
    public void create(UserWeightLog userWeightLog) {
        userWeightLogDao.insert(userWeightLog);
    }

    @Override
    public void updateByOrderNo(UserWeightLog userWeightLog) {
        userWeightLogDao.updateByOrderNo(userWeightLog);
    }

    @Override
    public void deleteExcessData(Integer userId) {
        if (this.getCount(userId) > 40) {
            userWeightLogDao.deleteOldest(userId);
        }
    }

    @Override
    public int getCount(Integer userId) {
        return userWeightLogDao.selectCount(userId);
    }
}
